class Book(val title: String, val author: String, val isbn: String) {
  private var borrowed: Boolean = false

  def borrow(): Boolean = {
    if (!borrowed) {
      borrowed = true
      true
    } else {
      false
    }
  }

  def returnBook(): Boolean = {
    if (borrowed) {
      borrowed = false
      true
    } else {
      false
    }
  }
}
class Library {
  private var availableBooks: List[Book] = List()
  private var borrowedBooks: List[Book] = List()

  def addBook(book: Book): Unit = {
    availableBooks = book :: availableBooks
  }

  def borrowBook(isbn: String): Boolean = {
    for (book <- availableBooks) {
      if (book.isbn == isbn && book.borrow()) {
        availableBooks = availableBooks.filterNot(_ == book)
        borrowedBooks = book :: borrowedBooks
        return true
      }
    }
    false
  }

  def returnBook(isbn: String): Boolean = {
    for (book <- borrowedBooks) {
      if (book.isbn == isbn && book.returnBook()) {
        borrowedBooks = borrowedBooks.filterNot(_ == book)
        availableBooks = book :: availableBooks
        return true
      }
    }
    false
  }
}
object LibrarySystem {
  def main(args: Array[String]): Unit = {
    val library = new Library()
    val book1 = new Book("Scala编程", "Martin Odersky", "978-1234567890")
    val book2 = new Book("Java编程", "James Gosling", "978-0987654321")
    library.addBook(book1)
    library.addBook(book2)
    println(library.borrowBook("978-1234567890"))
    println(library.borrowBook("978-0987654321")) 
    println(library.borrowBook("978-1234567890"))  
    println(library.returnBook("978-1234567890"))
    println(library.returnBook("978-0987654321")) 
    println(library.returnBook("978-1234567890")) 
  }
}

